package site.enjoyrun.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import site.enjoyrun.mapper.UserMapper;
import site.enjoyrun.model.User;
import site.enjoyrun.service.UserService;

import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;

@Service("userService")
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper userMapper;
    @Override
    public List<User> getAllUser() {
        List<User> users = null;
        try {
            users = userMapper.selectUsers();;
        } catch (Exception e) {
            System.out.println(e);
        }
        return users;
    }

    @Override
    public boolean insertUser(User user) {
        boolean res = false;
        try {
            res = userMapper.insertUser(user) > 0;
        } catch (Exception e) {
            System.out.println(e);
        }
        return res;
    }

    @Override
    public boolean updateUser(User user) {
        boolean res = false;
        try {
            res = userMapper.updateUser(user) > 0;
        } catch (Exception e) {
            System.out.println(e);
        }
        return res;
    }

    @Override
    public boolean deleteUser(String uId) {
        boolean res = false;
        try {
            res = userMapper.deleteUser(uId) > 0;
        } catch (Exception e) {
            System.out.println(e);
        }
        return res;
    }
}
